#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_ecphosph.info <<'%EOF%'
   rsp_ecphosph
   -------------
   Molecule:         C2H4
   Wave Function:    MCSCF (CAS) / ANO (Atombasis)
   Test Purpose:     Effective charge spin-orbit and phosphorescence
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > rsp_ecphosph.mol <<'%EOF%'
ATOMBASIS
AMFI spin-orbit and phosphorescence

    2    3  X  Y  Z 1 1.00D-12
        6.0   1 Basis=ano-1 3 2 0 0 
C             0.000000       0.000000       1.257892
        1.0   1 Basis=ano-1 2 1 0 0 
H             0.000000       1.745462       2.342716
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_ecphosph.dal <<'%EOF%'
**DALTON INPUT
.RUN RESPONS
**WAVE FUNCTIONS
.HF
.MP2
.MCSCF
*SCF INPUT
.DOUBLY OCCUPIED
 3 1 1 0 2 0 1 0                  
*CONFIGURATION INPUT
.INACTIVE
 1 0 0 0 1 0 0 0 
.ELECTRONS
 12  
.CAS SPACE
 3 1 2 0 3 1 2 0     
.SYMMET
 1
.SPIN MULT
 1
*OPTIMIZATION
.DETERMINANTS
**RESPONS
*QUADRATIC
.ECPHOS                
.PRINT
 5  
.ROOTS
  0 0 0 0 1 0 0 0 
**END OF INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >rsp_ecphosph.check
cat >>rsp_ecphosph.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# Basis set
CRIT1=`$GREP "C * 2 * 6\.0000 * 41 * 9 * \[14s9p\|3s2p\]" $log | wc -l`
CRIT2=`$GREP "H * 4 * 1\.0000 * 20 * 5 * \[8s4p\|2s1p\]" $log | wc -l`
CRIT3=`$GREP "total\: * 6 * 16\.0000 * 162 * 38" $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[1]=3
ERROR[1]="BASIS SET NOT READ CORRECTLY"

# Geometry
CRIT1=`$GREP "1 * x * (0| )\.0000000000" $log | wc -l`
CRIT2=`$GREP "2 * y * (0| )\.0000000000" $log | wc -l`
CRIT3=`$GREP "3 * z * 1\.2578920000" $log | wc -l`
CRIT4=`$GREP "4 * x * (0| )\.0000000000" $log | wc -l`
CRIT5=`$GREP "5 * y * (0| )\.0000000000" $log | wc -l`
CRIT6=`$GREP "6 * z * \-1\.2578920000" $log | wc -l`
CRIT7=`$GREP "7 * x * (0| )\.0000000000" $log | wc -l`
CRIT8=`$GREP "8 * y * 1\.7454620000" $log | wc -l`
CRIT9=`$GREP "9 * z * 2\.3427160000" $log | wc -l`
CRIT10=`$GREP "10 * x * (0| )\.0000000000" $log | wc -l`
CRIT11=`$GREP "11 * y * \-1\.7454620000" $log | wc -l`
CRIT12=`$GREP "12 * z * 2\.3427160000" $log | wc -l`
CRIT13=`$GREP "13 * x * (0| )\.0000000000" $log | wc -l`
CRIT14=`$GREP "14 * y * 1\.7454620000" $log | wc -l`
CRIT15=`$GREP "15 * z * \-2\.3427160000" $log | wc -l`
CRIT16=`$GREP "16 * x * (0| )\.0000000000" $log | wc -l`
CRIT17=`$GREP "17 * y * \-1\.7454620000" $log | wc -l`
CRIT18=`$GREP "18 * z * \-2\.3427160000" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12 \+ \
		$CRIT13 \+ $CRIT14 \+ $CRIT15 \+ $CRIT16 \+ $CRIT17 \+ $CRIT18`
CTRL[2]=18
ERROR[2]="GEOMETRY NOT READ CORRECTLY"

# Symmetry
CRIT1=`$GREP "Number of coordinates in each symmetry\: * 3 * 2 * 3 * 1 * 3 * 2 * 3 * 1" $log | wc -l`
CRIT2=`$GREP "Number of orbitals in each symmetry\: * 9 * 3 * 6 * 1 * 9 * 3 * 6 * 1" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2`
CTRL[3]=2
ERROR[3]="SYMMETRY NOT CORRECT"

# Energy
CRIT1=`$GREP "Final MCSCF energy\: * \-78\.1785072190[0-9][0-9]" $log | wc -l`
TEST[5]=`expr	$CRIT1`
CTRL[5]=1
ERROR[5]="MCSCF ENERGY NOT CORRECT"

# Response setup
CRIT1=`$GREP "Phosphorescence calculation requested with effective charge spin-orbit operator." $log | wc -l`
CRIT2=`$GREP "Spin of operator A \, ISPINA\= * 0" $log | wc -l`
CRIT3=`$GREP "Spin of operator B \, ISPINB\= * 1" $log | wc -l`
CRIT4=`$GREP "Spin of operator C \, \(Excitation energy\) ISPINC\= * 1" $log | wc -l`
CRIT5=`$GREP "1 B\-frequencies * (0| )\.000000(D|E)\+00" $log | wc -l`
CRIT6=`$GREP "1 A OPERATORS OF SYMMETRY NO\: * 2 AND LABELS\:" $log | wc -l`
CRIT7=`$GREP "1 A OPERATORS OF SYMMETRY NO\: * 3 AND LABELS\:" $log | wc -l`
CRIT8=`$GREP "1 B OPERATORS OF SYMMETRY NO\: * 6 AND LABELS\:" $log | wc -l`
CRIT9=`$GREP "1 B OPERATORS OF SYMMETRY NO\: * 7 AND LABELS\:" $log | wc -l`
TEST[6]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9`
CTRL[6]=9
ERROR[6]="RESPONSE CALCULATION NOT SET UP CORRECTLY"

# Quadratic response
CRIT1=`$GREP "\@ *QRLRVE\: * << XDIPLEN * \; XDIPLEN * >> \( * (0| )\.16645\)\: * 15\.238...[0-9][0-9]" $log | wc -l`
CRIT2=`$GREP "\@ *QRLRVE\: * << YDIPLEN * \; YDIPLEN * >> \( * (0| )\.16645\)\: * 2(0| )\.734...[0-9][0-9]" $log | wc -l`
TEST[7]=`expr	$CRIT1 \+ $CRIT2`
CTRL[7]=2
ERROR[7]="QUADRATIC RESPONSE NOT CORRECT"

# Phosphorescence
CRIT1=`$GREP "Partial rates \(ECSO\)\: X\-polarization * 0\.254[0-9]" $log | wc -l`
CRIT2=`$GREP "Partial rates \(ECSO\)\: Y\-polarization * 2\.848[0-9]*(D|E)\-03" $log | wc -l`
CRIT3=`$GREP "Partial rates \(ECSO\)\: Z\-polarization * (0| )\.(    |000)" $log | wc -l`
CRIT4=`$GREP "Total transition * rate * \(ECSO\) * 8\.57[0-9]*(D|E)\-02 s\-1" $log | wc -l`
CRIT5=`$GREP "Total phosphorescence lifetime * \(ECSO\) * 1\.16[0-9]*(D|E)\+01 s" $log | wc -l`
TEST[8]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5`
CTRL[8]=5
ERROR[8]="PHOSPHORESCENCE NOT CORRECT"

PASSED=1
for i in 1 2 3 5 6 7 8
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
